//
//  GetMoneyViewController.m
//  ShangAPP
//
//  Created by 徐番茄丶 on 16/1/22.
//  Copyright © 2016年 wangdao. All rights reserved.
//

#import "GetMoneyViewController.h"
#import "MyTools.h"

@interface GetMoneyViewController ()
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UITextField *moneyfield;
@property (weak, nonatomic) IBOutlet UIButton *mybtn;
@property (weak, nonatomic) IBOutlet UILabel *titlelab;

@end

@implementation GetMoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = [NSString stringWithFormat:@"提现到%@",_isHow];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    [self.navigationItem.leftBarButtonItem setTintColor:UIColorFromRGB(0x444444)];
    
    
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    
    self.view.backgroundColor = UIColorFromRGB(0xefeff1);
    
    [self viewCreate];
}



-(void)viewCreate{
    if (_isWhere == 0) {
        //余额
        _titlelab.text = @"我的余额";
        _moneyLab.text = [NSString stringWithFormat:@"￥%@",_moneyStr];
        _moneyfield.placeholder = [NSString stringWithFormat:@"可提现金额￥%@",_moneyStr];
    }else if (_isWhere == 1){
        //积分
        _titlelab.text = @"我的积分";
        _moneyLab.text = [NSString stringWithFormat:@"%@",_fenStr];
        
        _moneyfield.placeholder = [NSString stringWithFormat:@"%d积分=1元现金",_isDuiHuan];
    }
}


- (IBAction)getmoney:(id)sender {
    
    NSString *url = @"http://www.xsy777.com/app/merchant/withdrawadd.html";
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    
    [dic setObject:[user objectForKey:@"token"] forKey:@"user_token"];
    [dic setObject:_moneyfield.text forKey:@"price"];
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    if (_isWhere == 0) {
        [dic setObject:@"2" forKey:@"types"];
    }else if (_isWhere == 1){
        [dic setObject:@"3" forKey:@"types"];
    }
    
    if ([_isHow isEqualToString:@"支付宝"]) {
        [dic setObject:@"1" forKey:@"pay_status"];
    }else if ([_isHow isEqualToString:@"微信"]){
        [dic setObject:@"2" forKey:@"pay_status"];
    }
    
    AFHTTPRequestOperationManager *manager = [MyTools initAFHttpManager];
    
    [manager POST:url parameters:dic success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if ([[responseObject objectForKey:@"status"] intValue] == 1) {
            //[self.view makeToast:@"操作成功" duration:1.0 position:CSToastPositionCenter];
            
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [self.view makeToast:[responseObject objectForKey:@"info"] duration:1.0 position:CSToastPositionCenter];
        }
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if ([MyTools connectedToNetwork] == 0) {
            [self.view makeToast:@"请检查是否联网" duration:1.0 position:CSToastPositionCenter];
        }else{
            [self.view makeToast:@"服务器错误，再试一次" duration:1.0 position:CSToastPositionCenter];
        }
    }];
}






-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.translucent = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
